<?php

/**
 * This is the model class for table "PAYMENTS".
 *
 * The followings are the available columns in table 'PAYMENTS':
 * @property string $PAYMENT_ID
 * @property string $CUSTOMER_ID
 * @property integer $PAYMENT_TYPE_ID
 * @property string $AMOUNT
 * @property string $TRANSACTION_ID
 * @property string $CREATED_DATE
 */
class Payments extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Payments the static model class
	 */
	 
	public $PAYMENT_NAME;
	
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'PAYMENTS';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('PAYMENT_TYPE_ID', 'numerical', 'integerOnly'=>true),
			array('CUSTOMER_ID, AMOUNT', 'length', 'max'=>19),
			array('CREATED_DATE', 'length', 'max'=>10),
		  array('TRANSACTION_ID','length','max' => 50),
			array('CREATED_DATE','default','value'=> new CDbExpression('GETDATE()'),'setOnEmpty'=>false,'on'=>'insert'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'cUSTOMER' => array(self::BELONGS_TO, 'CUSTOMERS', 'CUSTOMER_ID'),
			'pAYMENTTYPE' => array(self::BELONGS_TO, 'PAYMENTTYPES', 'PAYMENT_TYPE_ID'),
			'cUSTOMERCCSs' => array(self::HAS_MANY, 'CUSTOMERCCS', 'PAYMENT_ID'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'PAYMENT_ID' => 'Payment',
			'CUSTOMER_ID' => 'Customer',
			'PAYMENT_TYPE_ID' => 'Payment Type',
			'AMOUNT' => 'Amount',
			'TRANSACTION_ID' => 'Transaction',
			'CREATED_DATE' => 'Created Date',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('PAYMENT_ID',$this->PAYMENT_ID,true);
		$criteria->compare('CUSTOMER_ID',$this->CUSTOMER_ID,true);
		$criteria->compare('PAYMENT_TYPE_ID',$this->PAYMENT_TYPE_ID);
		$criteria->compare('AMOUNT',$this->AMOUNT,true);
		$criteria->compare('TRANSACTION_ID',$this->TRANSACTION_ID,true);
		$criteria->compare('CREATED_DATE',$this->CREATED_DATE,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}